package com.content.scaffold.common.delegate.event;

import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.common.engine.api.delegate.event.FlowableEventType;

import java.util.Collection;

import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.JOB_EXECUTION_FAILURE;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.JOB_EXECUTION_SUCCESS;

/**
 * @author xiaojl
 */
public class MyEventListener implements FlowableEventListener {
    @Override
    public void onEvent(FlowableEvent flowableEvent) {
        FlowableEventType type = flowableEvent.getType();
        if (type.equals(JOB_EXECUTION_SUCCESS)) {
            System.out.println("A job well done!");
        } else if (type.equals(JOB_EXECUTION_FAILURE)) {
            System.out.println("A job has failed...");
        } else {
            System.out.println("Event received: " + flowableEvent.getType());
        }
    }

    @Override
    public boolean isFailOnException() {
        return false;
    }

    @Override
    public boolean isFireOnTransactionLifecycleEvent() {
        return false;
    }

    @Override
    public String getOnTransaction() {
        return "";
    }

    @Override
    public Collection<? extends FlowableEventType> getTypes() {
        return FlowableEventListener.super.getTypes();
    }
}
